package com.hkts.naturalgas.organizational.controller;


import com.hkts.naturalgas.organizational.entity.HontDepartment;
import com.hkts.naturalgas.organizational.orgVo.DepartmentAndUserVo;
import com.hkts.naturalgas.organizational.orgVo.HontDepartmentAndUserVo;
import com.hkts.naturalgas.organizational.orgVo.PossessDepartVo;
import com.hkts.naturalgas.organizational.service.IHontDepartmentService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2020-12-23
 */
@RestController
@RequestMapping("/performance/hontDepartment")
public class HontDepartmentController {
    private final Logger logger = LoggerFactory.getLogger(HontDepartmentController.class);

    @Autowired
    public IHontDepartmentService iHontDepartmentService;

    /**
     * 分页查询数据
     *
     * @param page           分页信息
     * @param hontDepartment 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHontDepartmentPageList")
    public Result<Object> getHontDepartmentPageList(Page<HontDepartment> page, HontDepartment hontDepartment) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHontDepartmentService.selectPage(page, hontDepartment)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hontDepartment 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hontDepartmentSave")
    public Result<Object> hontDepartmentSave(HontDepartment hontDepartment) {
        iHontDepartmentService.saveOrUpdate(hontDepartment);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hontDepartmentGetById")
    public Result<Object> hontDepartmentGetById(String id) {
        HontDepartment byId = iHontDepartmentService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hontDepartmentDelete")
    public Result<Object> hontUserDelete(String id) {
        iHontDepartmentService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hontDepartmentBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHontDepartmentService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
   /*
   *
   * 根据用户权限获取半及操作员
   * */
   @ResponseBody
   @RequestMapping(method = RequestMethod.GET, value = "/getHontUserAndTeam")
   public Result<Object> getHontUserAndTeam() {
       List<HontDepartmentAndUserVo> list=iHontDepartmentService.getHontUserAndTeam();
       return ResultUtil.data(list);
   }
    /*
     *
     * 根据用户权限获取部门列表
     * */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getHontUserPossess")
    public Result<Object> getHontUserPossess() {
        List<PossessDepartVo> hontUserPossess = iHontDepartmentService.getHontUserPossess();
        return ResultUtil.data(hontUserPossess);
    }

    /*
     *
     * 获取部门列表
     * */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getAllParentDepart")
    public Result<Object> getAllParentDepart() {
        List<HontDepartment> allParentDepart = iHontDepartmentService.getAllParentDepart();
        HontDepartment hontDepartment = new HontDepartment();
        hontDepartment.setTitle("全部");
        allParentDepart.add(hontDepartment);
        return ResultUtil.data(allParentDepart);
    }

}
